<template>
  <div class="manage">
    <div class="manage_box">
      <div class="btn_box">
        <el-button type="primary" class="exc" @click="daochu">excel导出</el-button>
         <el-button type="success" class="exc" @click="daoru">excel导入</el-button>
      </div>
    </div>
    <!-- 表格 -->
    <el-table :data="tableData" border style="width: 100%" id="table">
      <el-table-column type="index" label="#" />
      <el-table-column prop="username" label="姓名" />
      <el-table-column prop="mobile" label="联系方式" />
      <el-table-column prop="role[0].title" label="角色" />
       <el-table-column prop="avatar" label="头像" >
         <template #default="{ row }">
          <el-avatar
        :src="row.avatar"
      />
        </template>
       </el-table-column>
      <el-table-column prop="openTime" label="开通时间" />
      <el-table-column fixed="right" label="操作" >
        <template #default>
          <el-button link type="primary" size="small" @click="del(id)">删除</el-button>
          <el-button link type="primary" size="small">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
  <el-pagination
      v-model:currentPage="query.page"
      v-model:page-size="query.size"
      :page-sizes="[1, 3, 5, 7]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script setup>
import { ref, reactive, onMounted } from "vue";
import { managelist ,setexcel} from "../../http/api";
import {getFullTime} from '../../http/time'
import {useRouter} from 'vue-router'
import { ElMessage } from 'element-plus'
import * as XLSX from "xlsx";
const query = reactive({
  page: 1,
  size: 2,
});
const total = ref(0)
const tableData = ref([]);
const router = useRouter()
onMounted(() => {
  getlist();
});

const getlist = async() => {

  var res = await managelist(query)
  console.log(555,res);
  tableData.value = res.data.list
  total.value = res.data.total
  res.data.list.forEach(item=>{
    // console.log(item.openTime);  //十二进制时间
    item.openTime = getFullTime ( Number(item.openTime))
  })
};
const handleSizeChange = (val) => {
 query.size = val
 getlist();
}
const handleCurrentChange = (val) => {
 query.page = val
 getlist();
}

//导入
const daoru =()=>{
  console.log(123);
  router.push('/user/import')
}

//导出
const daochu =()=>{
  let workbook = XLSX.utils.table_to_book(document.getElementById("table")); //需要在table上定义一个id
  try {
    XLSX.writeFile(workbook, "员工信息表.xlsx");
    ElMessage({
      type: "success",
      message: "导出成功!",
    });
  } catch (e) {
    ElMessage.error("导出失败,失败信息:!");
  }
}
</script>
<style lang="scss">
.manage_box {
  width: 100%;
  height: 80px;
  background: #ffffff;
  box-shadow: 0 0 8px #ccc;
  margin: auto;
  border-radius: 10px;
  line-height: 80px;
}
.exc {
  float: right;
  margin-top: 20px;
  margin-left: 20px;
}
.btn_box {
  margin-right: 100px;
}
</style>